import { inject } from "inversify";
import { controller, httpGet, httpPost } from "inversify-express-utils";
import { Request, Response } from "express";
import Result from "../../utils/Result";
import { MessageService } from "./service";
import { MessageDto } from "./message.dto";

@controller("/message")
export class MessageController {
  constructor(@inject(MessageService) private server: MessageService) {}

  @httpPost("/send")
  async send(req: Request, res: Response) {
    const message = req.body as MessageDto;
    const result = await this.server.send(message);
    res.json(Result.ok(result));
  }

  @httpGet("/list")
  async list(req: Request, res: Response) {
    const result = await this.server.list();
    res.json(Result.ok(result));
  }
}
